< previous page page_289 next page >

Page 289
z0309-01.gif
Figure 10.7
Snowflakes of depth 1, 2, and 3.
Whenever the program must recursively draw a line segment, it draws segments that are scaled down by some factor. The program can store this factor in the variable ScaleFactor.
For example, consider the generator and initiator in Figure 10.6. When the program recursively draws a line segment, it begins by drawing a third of the length of the segment in its current direction. It then turns 60 degrees and draws another third of the length of the segment. Next, it turns 120 degrees and draws another third. Finally, it turns 60 degrees again and draws yet another third of the length of the original segment. In this case, you could use the following code to initialize the generator data. In this case, you could use the following code to initialize the generator data.
e10a6a0a59f035e870d90cca05b85fce.gif
ScaleFactor = 1/3                 ' Make subsegments 1/3 size.
GeneratorDTheta(1) = 0            ' Draw in original direction.
GeneratorDTheta(2) = PI / 3       ' Turn 60 degrees.
GeneratorDTheta(3) = -2 * PI / 3  ' Turn -120 degrees.
GeneratorDTheta(4) = PI / 3       ' Turn 60 degrees. 
GeneratorDTheta(4) = PI /3        ' Turn 60 degrees
Using the generator array GeneratorDTheta and the value ScaleFactor, you can write a subroutine to draw a segment in the snowflake. The DrawFlakeEdge routine shown in the following code recursively draws a segment that starts at position (x1, y1) and moves in the direction theta by distance dist. When it is finished, it leaves the values x1 and y1 so they indicate the endpoint of the segment. That makes it easier to perform all of the necessary recursive calls one after another.
e10a6a0a59f035e870d90cca05b85fce.gif
' Recursively draw a snowflake edge starting at
' (x1, y1) in direction theta and distance dist.
' Leave the coordinates of the endpoint in
' (x1, y1).
Private Sub DrawFlakeEdge(ByVal depth As Integer, _
    ByRef x1 As Single, ByRef y1 As Single, _
    ByVal theta As Single, ByVal dist As Single)
Dim status As Integer
Dim i As Integer
Dim x2 As Single
Dim y2 As Single

 
< previous page page_289 next page >